﻿Public Class oCustomerPropertyDetail

    Public Function UpdateJsonCustomerPropertyDetail(ByVal propertyID As String, _
                                    ByVal propertyDetailCode As String, ByVal propertyDetailName As String, ByVal propertyDetailID As String, _
                                    ByVal createdUserId As String, ByVal databaseName As String, ByVal isInsert As Boolean) As String
        Dim connect As New Connection()
        Try
            Dim errMsg As String = connect.setSQLDB(databaseName)
            If errMsg.Length = 0 Then
                Dim params = New Object() {propertyID, propertyDetailCode, propertyDetailName, createdUserId}
                Dim query As New StringBuilder
                If isInsert = True Then
                    query.Append(" INSERT INTO [oCustomerPropertyDetail]")
                    query.Append("  ([PropertyID]")
                    query.Append(" ,[PropertyDetailCode]")
                    query.Append(" ,[PropertyDetailName]")
                    query.Append(" ,[CreatedUserID])")
                    query.Append("VALUES (@Param1,@Param2,@Param3,@Param4)")
                    Dim count As Integer = connect.Object_Execute_SAP(query.ToString(), params)
                Else
                    query.Append("UPDATE  [oCustomerPropertyDetail] SET ")
                    query.Append("  [PropertyDetailCode] = @Param1, [PropertyDetailName] = @Param2")
                    query.Append("  ,[PropertyID] = @Param3")
                    query.Append(" WHERE [PropertyDetailID] = @Param4")
                    connect.Object_Execute_SAP(query.ToString(), New Object() {propertyDetailCode, propertyDetailName, propertyID, propertyDetailID})
                End If
            Else
                Return errMsg
            End If
        Catch ex As Exception

            Return ex.Message
        End Try
        Return String.Empty
    End Function
    Public Function DeleteJsonCustomerPropertyDetail(ByVal dataBaseName As String, ByVal propertyDetailID As String) As String
        Dim connect As New Connection()
        Try
            Dim errMsg As String = connect.setSQLDB(databaseName)
            If errMsg.Length = 0 Then
                Dim params = New Object() {propertyDetailID}
                Dim query As New StringBuilder
                query.Append(" DELETE FROM [oCustomerPropertyDetail]")
                query.Append("  WHERE oCustomerPropertyDetail.PropertyDetailID =  @Param1")
                Dim count As Integer = connect.Object_Execute_SAP(query.ToString(), params)
            Else
                Return errMsg
            End If
        Catch ex As Exception

            Return ex.Message
        End Try
        Return String.Empty
    End Function
    Public Function GetAllCustomerPropertyDetailByPropertyID(ByVal dataBaseName As String, ByVal propertyID As String) As DataSet
        Dim connect As New Connection()
        Try
            Dim ds As New DataSet("oCustomerPropertyDetail")
            Dim errMsg As String = connect.setSQLDB(dataBaseName)
            Dim query As New StringBuilder
            If errMsg.Length = 0 Then
                query.Append("SELECT * FROM oCustomerPropertyDetail T0 JOIN oCustomerProperty T1 ON T0.PropertyID = T1.PropertyID ")
                query.Append(" JOIN oUser T2 ON T0.CreatedUserID = T2.UserID ")
                query.Append(" JOIN oCompany T3 ON T3.CompanyCode = T1.CompanyCode ")
                query.Append(" WHERE T0.PropertyID  =  @Param1")
                query.Append("  ORDER BY T0.PropertyDetailID DESC")
                ds = connect.ObjectGetAll_Query_SAP(query.ToString(), New Object() {propertyID})
            End If
            Return ds
        Catch ex As Exception
            Throw ex
        End Try
    End Function
    Public Function GetAllCustomerPropertyDetail(ByVal dataBaseName As String, ByVal companyCode As String) As DataSet
        Dim connect As New Connection()
        Try
            Dim ds As New DataSet("oCustomerPropertyDetail")
            Dim errMsg As String = connect.setSQLDB(dataBaseName)
            Dim query As New StringBuilder
            If errMsg.Length = 0 Then
                query.Append("SELECT * FROM oCustomerPropertyDetail T0 JOIN oCustomerProperty T1 ON T0.PropertyID = T1.PropertyID ")
                query.Append(" JOIN oUser T2 ON T0.CreatedUserID = T2.UserID ")
                query.Append(" JOIN oCompany T3 ON T3.CompanyCode = T1.CompanyCode ")
                query.Append(" WHERE T1.CompanyCode = @Param1")
                query.Append("  ORDER BY T0.PropertyDetailID DESC")
                ds = connect.ObjectGetAll_Query_SAP(query.ToString(), New Object() {companyCode})
            End If
            Return ds
        Catch ex As Exception
            Throw ex
        End Try
    End Function
    Public Function GetCustomerPropertyDetail(ByVal dataBaseName As String) As DataSet
        Dim connect As New Connection()
        Try
            Dim ds As New DataSet("oCustomerPropertyDetail")
            Dim errMsg As String = connect.setSQLDB(dataBaseName)
            Dim query As New StringBuilder
            If errMsg.Length = 0 Then
                query.Append("SELECT * FROM oCustomerPropertyDetail T0 JOIN oCustomerProperty T1 ON T0.PropertyID = T1.PropertyID ")
                query.Append(" JOIN oUser T2 ON T0.CreatedUserID = T2.UserID ")
                query.Append(" JOIN oCompany T3 ON T3.CompanyCode = T1.CompanyCode ")
                query.Append("  ORDER BY T0.PropertyDetailID DESC")
                ds = connect.ObjectGetAll_Query_SAP(query.ToString())
            End If
            Return ds
        Catch ex As Exception
            Throw ex
        End Try
    End Function
End Class
